package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.PatientDAO;
import org.gap.dao.RendezVousDAO;

import org.gap.domain.Patient;
import org.gap.domain.RendezVous;

import org.gap.service.RendezVousService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for RendezVous entities
 * 
 */
@Scope("session")
@Component("RendezVousComponent")
public class RendezVousComponentImpl implements RendezVousComponent {

	/**
	 * Data type variable that provides CRUD operations for RendezVous entities
	 * 
	 */
	private RendezVous rendezvous;

	/**
	 * DAO injected by Spring that manages Patient entities
	 * 
	 */
	private Patient patient;

	/**
	 * DAO injected by Spring that manages Patient entities
	 * 
	 */
	@Autowired
	private PatientDAO patientDAO;

	/**
	 * DAO injected by Spring that manages RendezVous entities
	 * 
	 */
	@Autowired
	private RendezVousDAO rendezVousDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for RendezVous entities
	 * 
	 */
	@Autowired
	private RendezVousService rendezVousService;

	/** 
	 */
	public RendezVousComponentImpl() {
	}

	/**
	 * Edit an existing Patient entity
	 * 
	 */
	@Transactional
	public String editRendezVousPatient(Integer rendezvous_rdvRendezVous, Integer related_patient_patPatient) {
		patient = patientDAO.findPatientByPrimaryKey(related_patient_patPatient, -1, -1);
		return "/jsf/rendezvous/patient/editPatient.xhtml";
	}

	/**
	 * Select the child Patient entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRendezVousPatient(Integer rendezvous_rdvRendezVous, Integer related_patient_patPatient) {
		patient = patientDAO.findPatientByPrimaryKey(related_patient_patPatient);

		return "/jsf/rendezvous/patient/deletePatient.xhtml";
	}

	/**
	 * Getter for variable RendezVous
	 * 
	 */
	@Transactional
	public RendezVous getRendezvous() {
		return rendezvous;
	}

	/**
	 * Delete an existing Patient entity
	 * 
	 */
	@Transactional
	public String deleteRendezVousPatient(Integer rendezvous_rdvRendezVous, Integer related_patient_patPatient) {
		rendezvous = rendezVousService.deleteRendezVousPatient(rendezvous_rdvRendezVous, related_patient_patPatient);

		return "/jsf/rendezvous/viewRendezVous.xhtml";
	}

	/**
	 * Create a new Patient entity
	 * 
	 */
	@Transactional
	public String newRendezVousPatient(Integer rendezvous_rdvRendezVous) {
		patient = new Patient();

		return "/jsf/rendezvous/patient/createPatient.xhtml";
	}

	/**
	 * Get Patient entity by RendezVous
	 * 
	 */
	@Transactional
	public Patient getRendezVousPatient(Integer rdvRendezVousKey) {
		return rendezVousDAO.findRendezVousByPrimaryKey(rdvRendezVousKey).getPatient();
	}

	/**
	 * Getter for variable RendezVous
	 * 
	 */
	@Transactional
	public Patient getPatient() {
		return patient;
	}

	/**
	 * Select an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String selectRendezVous(Integer rdvRendezVousKey) {
		rendezvous = rendezVousDAO.findRendezVousByPrimaryKey(rdvRendezVousKey);

		return "/jsf/rendezvous/viewRendezVous.xhtml";
	}

	/**
	 * Create a new RendezVous entity
	 * 
	 */
	@Transactional
	public String newRendezVous() {
		rendezvous = new RendezVous();

		return "/jsf/rendezvous/createRendezVous.xhtml";
	}

	/**
	 * Select the RendezVous entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRendezVous(Integer rdvRendezVousKey) {
		rendezvous = rendezVousDAO.findRendezVousByPrimaryKey(rdvRendezVousKey);

		return "/jsf/rendezvous/deleteRendezVous.xhtml";
	}

	/**
	 * Show all RendezVous entities
	 * 
	 */
	@Transactional
	public List<RendezVous> listRendezVouss() {
		return new java.util.ArrayList<RendezVous>(rendezVousService.loadRendezVouss());
	}

	/**
	 * Edit an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String editRendezVous(Integer rdvRendezVousKey) {
		rendezvous = rendezVousDAO.findRendezVousByPrimaryKey(rdvRendezVousKey);

		return "/jsf/rendezvous/editRendezVous.xhtml";
	}

	/**
	 * Save an existing Patient entity
	 * 
	 */
	@Transactional
	public String saveRendezVousPatient(Integer rendezvous_rdvRendezVous, Patient patient) {
		rendezvous = rendezVousService.saveRendezVousPatient(rendezvous_rdvRendezVous, patient);

		return "/jsf/rendezvous/viewRendezVous.xhtml";
	}

	/**
	 * Delete an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String deleteRendezVous(Integer rdvRendezVousKey) {
		RendezVous rendezvous = rendezVousDAO.findRendezVousByPrimaryKey(rdvRendezVousKey);
		rendezVousService.deleteRendezVous(rendezvous);
		return "/jsf/rendezvous/listRendezVouss.xhtml";
	}

	/**
	 * Save an existing RendezVous entity
	 * 
	 */
	@Transactional
	public String saveRendezVous(RendezVous rendezvous) {
		rendezVousService.saveRendezVous(rendezvous);
		return "/jsf/rendezvous/listRendezVouss.xhtml";
	}

	/**
	 * View an existing Patient entity
	 * 
	 */
	@Transactional
	public String selectRendezVousPatient(Integer rendezvous_rdvRendezVous, Integer related_patient_patPatient) {
		patient = patientDAO.findPatientByPrimaryKey(related_patient_patPatient, -1, -1);
		return "/jsf/rendezvous/patient/viewPatient.xhtml";
	}

}
